package thread;

// 方法三： 继承 Thread, 重写 run, 使用匿名内部类
public class demo3 {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("hello thread !");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("线程结束 !");
            }
        };
        System.out.println("线程3启动 !");
        t.start();

        for (int i = 0; i < 5; i++) {
            System.out.println("hello main !");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("主线程结束 !");
    }

}
